<template>
    <el-container>
        <el-header>
            <div class="right-panel-search">
                <div class="search-input">单号</div>
                <el-input v-model="master.order_no" placeholder="请输入单号" clearable @change="handleKeyDown" />
                <div class="search-input">状态</div>
                <el-select v-model="master.status" placeholder="状态" clearable>
                    <el-option label="待确认" :value="0"/>
                    <el-option label="已确认" :value="1"/>
                </el-select>
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter border @selection-change="selectionChange" :params="query" show-summary>
                <el-table-column type="selection" fixed width="50"></el-table-column>
                <el-table-column label="对账单编号" prop="order_no" align="center"></el-table-column>
                <el-table-column label="工厂" prop="referred_as" align="center"></el-table-column>
                <el-table-column label="应付金额" prop="total_money" align="center"></el-table-column>
                <el-table-column label="扣款金额" prop="deduct_money" align="center"></el-table-column>
                <el-table-column label="实付金额" prop="meet_money" align="center"></el-table-column>
                <el-table-column label="状态" prop="send_count" align="center">
                    <template #default="scope">
                        <el-tag v-if="scope.row.status==0" type="danger">未确认</el-tag>
                        <el-tag v-else type="success">已确认</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="添加时间" align="center" prop="create_time"></el-table-column>
                <el-table-column label="操作" fixed="right" align="center" width="80">
                    <template #default="scope">
                        <el-button-group style="display:flex;flex-direction:column">
                            <el-popconfirm title="是否确认该结算单吗？" @confirm="confirm(scope.row, scope.$index)" v-if="scope.row.status==0">
                                <template #reference>
                                    <el-button text type="primary" size="small" v-auth="'develop.confirm'">确认</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
</template>

<script>
export default {
	name: 'user',
	data() {
		return {
			apiObj: this.$API.inventory.billMaster,
            query:{
                status:0,
                order_type:3,
                is_local:1
            },
			selection: [],
			master: {
                order_no:null,
				status: 0,
			},
		}
	},
    mounted() {
	},
	methods: {
		//确定操作
		async confirm(row) {
			var reqData = { id: row.id }
			var res = await this.$API.inventory.confirm.post(reqData);
			if (res.code == 1) {
                this.$refs.table.refresh()
				this.$message.success("确定成功")
			} else {
				this.$alert(res.message, "提示", { type: 'error' })
			}
		},
		//搜索
		upsearch() {
            console.log('this.seatch :>> ', this.master);
			this.$refs.table.upData(this.master)
		},
        selectionChange(selection){
            this.selection = selection;
        },
        handleKeyDown() {
            this.upsearch()
        },
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}
</style>
